import 'package:flutter/material.dart';
import 'package:flutterappmydemo/utils/date_time_util.dart';
import 'package:provider/provider.dart';

class SliderDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    DateTimeUtil.test();






    return Scaffold(
      appBar: AppBar(
        title: Text('Slider示例'),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () {},
        ),
      ),
      body: Container(
        height: 500,
        alignment: AlignmentDirectional.center,
        color: Colors.white,
        margin: EdgeInsets.all(10),
        child: Column(
          children: <Widget>[
            ///
            Container(
              margin: EdgeInsets.only(top: 110),
              child: ChangeNotifierProvider<SliderChange>(
                create: (BuildContext context) {
                  return SliderChange();
                },
                child: Consumer<SliderChange>(
                  builder: (context, mSliderChange, _) {
                    return Slider(
                      value: mSliderChange._value,
                      onChanged: (double value) {
                        print('SliderDemo.build onChanged value=$value');
                        mSliderChange.change(value);
                      },
                      onChangeStart: (double value) {
                        print('SliderDemo.build onChangeStart value =$value');
                      },
                      onChangeEnd: (double value) {
                        print('SliderDemo.build onChangeEnd value =$value');
                      },
                      min: 0.0,
                      max: 10.0,
                      divisions: 10,
                      label: '${mSliderChange._value}',
                      activeColor: Colors.red,
                      inactiveColor: Colors.orange,
                    );
                  },
                ),
              ),
            ),

            ///
          ],
        ),
      ), // This
    );
  }
}

class SliderChange with ChangeNotifier {
  double _value = 0;

  void change(double value) {
    _value = value;
    notifyListeners();
  }
}
